package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-06-02
 * Time: 21:46
 */
public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("2. 借阅图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要借阅的图书的名字：");
        String name = scanner.nextLine();
        int sz = bookList.getBookSize();

        for (int i = 0; i < sz; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
               if(bookList.getBook(i).isState() == true) {
                   System.out.println("这本书已经被借走了。");
                   return;
               }else {
                   bookList.getBook(i).setState(true);
                   System.out.println("借阅成功！");
                   return;
               }
            }
        }
        System.out.println("你要借阅的图书不在书架上。");
    }
}
